package com.jeesite.modules.dataview.chaierweijin.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jeesite.common.config.Global;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.modules.dataview.chaierweijin.entity.ImportResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.dataview.chaierweijin.entity.DcSupImportData;
import com.jeesite.modules.dataview.chaierweijin.service.DcSupImportDataService;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;
import java.util.Map;

/**
 * 拆而未尽表Controller
 * @author dbl
 * @version 2022-08-04
 */
@Controller
@RequestMapping(value = "${adminPath}/dataview/dcSupImportData")
public class DcSupImportDataController extends BaseController {

	@Autowired
	private DcSupImportDataService dcSupImportDataService;

	@RequiresPermissions("dataview:dcSupImportData:view")
	@RequestMapping(value = {"cards", ""})
	public String cards(DcSupImportData dcSupImportData, Model model) {
		model.addAttribute("dcSupImportData", dcSupImportData);
		return "dataview/chaierweijin/cards";
	}

	@RequiresPermissions("dataview:dcSupImportData:view")
	@RequestMapping(value = {"pageOne", ""})
	public String pageOne(DcSupImportData dcSupImportData, Model model) {
		model.addAttribute("dcSupImportData", dcSupImportData);
		return "dataview/chaierweijin/pageOne";
	}
	@RequiresPermissions("dataview:dcSupImportData:view")
	@RequestMapping(value = {"pageTwo", ""})
	public String pageTwo(DcSupImportData dcSupImportData, Model model) {
		model.addAttribute("dcSupImportData", dcSupImportData);
		return "dataview/chaierweijin/pageTwo";
	}
	@RequiresPermissions("dataview:dcSupImportData:view")
	@RequestMapping(value = {"pageThree", ""})
	public String pageThree(DcSupImportData dcSupImportData, Model model) {
		model.addAttribute("dcSupImportData", dcSupImportData);
		return "dataview/chaierweijin/pageThree";
	}
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public DcSupImportData get(String id, boolean isNewRecord) {
		return dcSupImportDataService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("dataview:dcSupImportData:view")
	@RequestMapping(value = {"list", ""})
	public String list(DcSupImportData dcSupImportData, Model model) {
		dcSupImportData.setC28(new Date());
		model.addAttribute("dcSupImportData", dcSupImportData);
		return "dataview/chaierweijin/dcSupImportDataList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("dataview:dcSupImportData:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<DcSupImportData> listData(DcSupImportData dcSupImportData, HttpServletRequest request, HttpServletResponse response) {
		dcSupImportData.setPage(new Page<>(request, response));
		if (dcSupImportData.getC28()==null){
//			dcSupImportData.setC28Str(LocalDate.now().toString());
		}else{
			dcSupImportData.setC28Str(DateUtils.formatDate(dcSupImportData.getC28(),"yyyy-MM-dd"));
		}
		Page<DcSupImportData> page = dcSupImportDataService.findPage(dcSupImportData);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("dataview:dcSupImportData:view")
	@RequestMapping(value = "form")
	public String form(DcSupImportData dcSupImportData, Model model) {
		model.addAttribute("dcSupImportData", dcSupImportData);
		return "dataview/chaierweijin/dcSupImportDataForm";
	}

	/**
	 * 导入
	 * @param file
	 * @return
	 */
	@PostMapping(value = "importData")
	@ResponseBody
	public String importData(MultipartFile file, Date c28) {
		try {
			String message = dcSupImportDataService.importData(file, c28);
			return renderResult(Global.TRUE, "posfull:"+message);
		} catch (Exception ex) {
			return renderResult(Global.FALSE, "posfull:"+ex.getMessage());
		}
	}

	@RequestMapping(value = "query1")
	@ResponseBody
	public String query1(DcSupImportData dcSupImportData){
		ImportResult map = dcSupImportDataService.query1(dcSupImportData);
		return renderResult(Global.TRUE, "成功",map);
	}

	@RequestMapping(value = "query2")
	@ResponseBody
	public String query2(DcSupImportData dcSupImportData){
		Map<String,Object> map = dcSupImportDataService.query2(dcSupImportData);
		return renderResult(Global.TRUE, "成功",map);
	}

	@RequestMapping(value = "query3")
	@ResponseBody
	public Page<DcSupImportData> query3(DcSupImportData dcSupImportData, HttpServletRequest request, HttpServletResponse response){
		dcSupImportData.setPage(new Page<>(request, response));
		dcSupImportData.setPageSize(200);
		Page<DcSupImportData> page = dcSupImportDataService.query3(dcSupImportData);
		return page;
	}

	@RequestMapping(value = "query4")
	@ResponseBody
	public String query4(DcSupImportData dcSupImportData){
		Map<String,Object> map = dcSupImportDataService.query4(dcSupImportData);
		return renderResult(Global.TRUE, "成功",map);
	}

	@RequestMapping(value = "query5")
	@ResponseBody
	public String query5(DcSupImportData dcSupImportData){
		Map<String,Object> map = dcSupImportDataService.query5(dcSupImportData);
		return renderResult(Global.TRUE, "成功",map);
	}

	@RequestMapping(value = "query6")
	@ResponseBody
	public String query6(DcSupImportData dcSupImportData){
		Map<String,Object> map = dcSupImportDataService.query6(dcSupImportData);
		return renderResult(Global.TRUE, "成功",map);
	}

	@RequestMapping(value = "query7")
	@ResponseBody
	public Page<DcSupImportData> query7(DcSupImportData dcSupImportData, HttpServletRequest request, HttpServletResponse response){
		dcSupImportData.setPage(new Page<>(request, response));
		dcSupImportData.setPageSize(200);
		Page<DcSupImportData> page = dcSupImportDataService.query7(dcSupImportData);
		return page;
	}

	@RequestMapping(value = "query8")
	@ResponseBody
	public String query8(DcSupImportData dcSupImportData){
		Map<String,Object> map = dcSupImportDataService.query8(dcSupImportData);
		return renderResult(Global.TRUE, "成功",map);
	}
}